﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TowerDefense.Actors;


namespace TowerDefense
{
    public class World<E>
    {
        private Grid<E> gr;

        private static readonly int DEFAULT_ROWS = 10; //THis is for a 10x10Grid
        private static readonly int DEFAULT_COLS = 10;

        public World()
        {
            gr = (new BoundedGrid<E>(DEFAULT_ROWS, DEFAULT_COLS));
        }

        public World(Grid<E> g)
        {
            gr = g;
        }

        /**
    * Gets the grid managed by this world.
    * @return the grid
    */
        public Grid<E> getGrid()
        {
            return gr;
        }

        /**
         * Sets the grid managed by this world.
         * @param newGrid the new grid
         */
        public void setGrid(Grid<E> newGrid)
        {
            gr = newGrid;
            //repaint();
        }

        /**
 * Adds an occupant at a given location.
 * @param loc the location
 * @param occupant the occupant to add
 */
        public void add(Location loc, E occupant)
        {
            getGrid().put(loc, occupant);
        }

        /**
         * Removes an occupant from a given location.
         * @param loc the location
         * @return the removed occupant, or null if the location was empty
         */
        public E remove(Location loc)
        {
            E r = getGrid().remove(loc);
            return r;
        }

        public void step()
        {
            Grid<E> gr = getGrid();
            List<E> actors = new List<E>();
            foreach (Location loc in gr.getOccupiedLocations())
                actors.Add(gr.get(loc));

            //TODO: shouldnt matter if the grid is shared
            //foreach (Actor a in actors)
            //{
            //    // only act if another actor hasn't removed a
            //    if (a.getGrid() == gr)
            //        a.act();
            //}
        }
    }
}
